package com.example.demo1.pay.controller;

import com.example.demo1.pay.entity.FundIntercourse;
import com.example.demo1.pay.entity.Wallet;
import com.example.demo1.pay.req.IDReq;
import com.example.demo1.pay.req.RefundReq;
import com.example.demo1.pay.service.WalletService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 用户钱包 前端控制器
 * </p>
 *
 * @author gong
 * @since 2023-02-27
 */
@RestController
@RequestMapping("/pay/wallet")
public class WalletController {

    @Resource
    WalletService walletService;

    /**
     *  1.查询用户钱包余额
     */
    @GetMapping("/getFund/{userId}")
    public List<Wallet> getFund(@PathVariable("userId") Long userId) {
        return walletService.getFund(userId);
    }

    /**
     *  2.用户消费100元的接口
     */
    @GetMapping("/pay")
    public Boolean pay(IDReq req) throws Exception {
        req.setPayerWalletId("1");
        req.setPayerWalletId("2");
        req.setMoney(new BigDecimal(100L));
        return walletService.pay(req);
    }

    /**
     *  3.用户退款20元接口
     */
    @GetMapping("/refund")
    public Boolean refund(RefundReq req) throws Exception {
        req.setSerialNumber("112233");
        req.setMoney(new BigDecimal(20L));
        return walletService.refund(req);
    }

    /**
     * 4.查询用户钱包金额变动明细的接口
     */
    @GetMapping("/getFundIntercourse")
    public List<FundIntercourse> getFundIntercourse(IDReq req) throws Exception {
        req.setPayerWalletId("1");
        return walletService.getFundIntercourse(req.getPayerWalletId());
    }

}
